package de.carcophan.jimdb.ejb.entites;

import com.flicklib.domain.MovieSearchResult;
import com.flicklib.domain.MovieType;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

@Entity()
@Table(name = "MOVIES", uniqueConstraints =
@UniqueConstraint(columnNames = {"IDFORSITE"}))
public class Movie implements Serializable {

    @Id()
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long movieId;
    @OneToMany(mappedBy = "movie",cascade=CascadeType.ALL)
    private List<UserMovies> users;
    @NotNull
    @Pattern(regexp = "[0-9][0-9]*", message = "Must match IMDB ID pattern 'ttxxxxx'")
    private String idForSite;
    private String alternateTitle;
    private String description;
    private String originalTitle;
    private String title;
    @Enumerated(EnumType.STRING)
    private MovieType type;
    private String url;
    @Column(name = "YR")
    private Integer year;
    @Version
    private Integer version;

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public String getAlternateTitle() {
        return alternateTitle;
    }

    public void setAlternateTitle(String alternateTitle) {
        this.alternateTitle = alternateTitle;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getIdForSite() {
        return idForSite;
    }

    public void setIdForSite(String idForSite) {
        this.idForSite = idForSite;
    }

    public String getOriginalTitle() {
        return originalTitle;
    }

    public void setOriginalTitle(String originalTitle) {
        this.originalTitle = originalTitle;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public MovieType getType() {
        return type;
    }

    public void setType(MovieType type) {
        this.type = type;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Integer getYear() {
        return year;
    }

    public void setYear(Integer year) {
        this.year = year;
    }

    public Movie() {
    }

    public Movie(MovieSearchResult movieSearchResult) {
        this.alternateTitle = (movieSearchResult.getAlternateTitle());
        this.description = (movieSearchResult.getDescription());
        this.idForSite = (movieSearchResult.getIdForSite());
        this.originalTitle = (movieSearchResult.getOriginalTitle());
        this.title = (movieSearchResult.getTitle());
        this.type = (movieSearchResult.getType());
        this.url = (movieSearchResult.getUrl());
        this.year = (movieSearchResult.getYear());
    }

    public Long getMovieId() {
        return movieId;
    }

    public void setMovieId(Long movieId) {
        this.movieId = movieId;
    }

    public List<UserMovies> getUsers() {
        return users;
    }

    public void setUsers(List<UserMovies> users) {
        this.users = users;
    }

   

    @Override
    public String toString() {
        return "Movie{ " + "movieId=" + movieId + ", idForSite=" + idForSite + ", alternateTitle=" + alternateTitle + ", description=" + description + ", originalTitle=" + originalTitle + ", title=" + title + ", type=" + type + ", url=" + url + ", year=" + year + '}';
    }
}
